package com.training.admin.entity.search;

import java.util.Date;
import java.util.Map;

import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 *
 * @author Rockett
 *
 */
public class ProjectAppraisalReportSearch extends ReportSearch {

    /** 编号 */
    private String code;
    
    /** 名称 */
    private String name;
    
    /** 分类  */
    private Long firstCategoryId;

    private Long secondCategoryId;

    /** 总期数 */
    private String phaseCount;
    
    /** 项目负责人*/
    private String projectLead;
    
    /** 事业部*/
    private Long departmentId;
    
    /**开始时间 从*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDateFrom;
    /**结束时间 到*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDateTo;
    /**结束时间 从*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDateFrom;
    /**开始时间 到*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDateTo;
    
    /** email */
    private String email;

    private QueryFilter filter;
    
    private QueryOrder order;

    
    /**
     * The default constructor
     */
    public ProjectAppraisalReportSearch() {
        order = new QueryOrder("p.name", "asc");
    }
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
    	
        if (filter == null || refresh) {
        	
            filter = new QueryFilter().addLike("code", code)
					.addLike("p.projectLead", projectLead)
					.addEquals("p.firstCategory","id", firstCategoryId)
					.addEquals("p.secondCategory","id", secondCategoryId)
					.addEquals("p.department","id", departmentId)
					.addEquals("p.phaseCount", phaseCount)
					.addDateBetween("p.beginDate", beginDateFrom, beginDateTo)
					.addDateBetween("p.endDate", endDateFrom, endDateTo)
                                      .addLike("p.name", name);
            
        }
        
        return filter;
        
    }
    
 
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM ProjectPhase as pp inner join pp.project as p with p.disabled = false where exists ( from TrainingSurveyResult as tsr where tsr.projectPhase.id = pp.id) " + getPreparedFilter(false).clauseSentence() + order.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}
    /**
     * 
     * @return
     */
    public QueryFilter getFilter(){
        return getPreparedFilter(false);
    }
	/**
	 * @return the order
	 */
	public QueryOrder getOrder() {
		return order;
	}
	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}
	/**
	 * @param code the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * @return the phaseCount
	 */
	public String getPhaseCount() {
		return phaseCount;
	}
	/**
	 * @param phaseCount the phaseCount to set
	 */
	public void setPhaseCount(String phaseCount) {
		this.phaseCount = phaseCount;
	}
	/**
	 * @return the projectLead
	 */
	public String getProjectLead() {
		return projectLead;
	}
	/**
	 * @param projectLead the projectLead to set
	 */
	public void setProjectLead(String projectLead) {
		this.projectLead = projectLead;
	}
	/**
	 * @return the departmentId
	 */
	public Long getDepartmentId() {
		return departmentId;
	}
	/**
	 * @param departmentId the departmentId to set
	 */
	public void setDepartmentId(Long departmentId) {
		this.departmentId = departmentId;
	}
	/**
	 * @return the firstCategoryId
	 */
	public Long getFirstCategoryId() {
		return firstCategoryId;
	}
	/**
	 * @param firstCategoryId the firstCategoryId to set
	 */
	public void setFirstCategoryId(Long firstCategoryId) {
		this.firstCategoryId = firstCategoryId;
	}
	/**
	 * @return the secondCategoryId
	 */
	public Long getSecondCategoryId() {
		return secondCategoryId;
	}
	/**
	 * @param secondCategoryId the secondCategoryId to set
	 */
	public void setSecondCategoryId(Long secondCategoryId) {
		this.secondCategoryId = secondCategoryId;
	}
	/**
	 * @return the beginDateFrom
	 */
	public Date getBeginDateFrom() {
		return beginDateFrom;
	}
	/**
	 * @param beginDateFrom the beginDateFrom to set
	 */
	public void setBeginDateFrom(Date beginDateFrom) {
		this.beginDateFrom = beginDateFrom;
	}
	/**
	 * @return the endDateTo
	 */
	public Date getEndDateTo() {
		return endDateTo;
	}
	/**
	 * @param endDateTo the endDateTo to set
	 */
	public void setEndDateTo(Date endDateTo) {
		this.endDateTo = endDateTo;
	}
	/**
	 * @return the endDateFrom
	 */
	public Date getEndDateFrom() {
		return endDateFrom;
	}
	/**
	 * @param endDateFrom the endDateFrom to set
	 */
	public void setEndDateFrom(Date endDateFrom) {
		this.endDateFrom = endDateFrom;
	}
	/**
	 * @return the beginDateTo
	 */
	public Date getBeginDateTo() {
		return beginDateTo;
	}
	/**
	 * @param beginDateTo the beginDateTo to set
	 */
	public void setBeginDateTo(Date beginDateTo) {
		this.beginDateTo = beginDateTo;
	}



}
